It can be done
If it's of any comfort, I'm in my 40s and I'm planning to leave a very well paid job in journalism to train as a pilot.
I've had to leave it this late because of problems regarding my vision and the Class 1 medical.
With me it's been a lifelong ambition but it all depends on your personal circumstances. If you can afford to take the (calculated) risk I would personally go for it. Once you're in your 50s I think it will be too late.
But you do need to think about it carefully -- have backup plans etc etc. For example, would you go and live in China or the ME if that's the only place you could get an FO job?