>Is there some kind of magic that makes engineers better when you take them out of India?
Yes, and it's called selection bias. A given engineer leaving their country gets no better, but the selection bias that applies to engineers who do leave their country means they are better on average. The good engineers who don't leave for some reason (family or such) are just as good as if they had left, but the average engineer is weighed down by those who don't have the skill to leave.
>And some of the worst developers I've worked with are Americans in America.
I've encountered some horrible American developers as well. The difference, in my experience, is that they tend to cost the same as a good American developer and thus get replaced a lot faster.