Overall, if you can get a connection of 2hrs, you'll be safe; but 40 mins might be really tight; especially considering that if you're first flight departs 10–15 mins late, you only have 25–30 mins, and depending on the airport, this definitely won't be enough.