But that’s not the only difference is it? You also moved the two strings to global declarations instead of passing them as arguments to the recursive function.
You were passing the strings by value too, which means each and every recursive call needs to make a copy of both strings. That’s gotta be slow. Try passing them by reference and see what difference that makes.
Disclaimer… It’s been a long time since I’ve done any serious C++. I might be talking rubbish.