I've realized that I had a lot of unprocessed events in one of my clients. Most of them due to a "missing subscription" error that occurred while trying to process IPN calls of subscription payments.
In particular, most of that payments were old and still had a transaction id like 123456/12/20190112345678. But the main problem is that most of them also had NULL in the contrib_recur_id of the civicrm_stripe_subscriptions table.
With this new query, if there was an id there, it will be still used. But if it wasn't, the value of the invoice_id will be used to find the corresponding recurring contribution.