I suspect that is has a lot to do with the varying IQ distributions between the genders. Females tend to be closer to the mean, whereas males have wider variance. If you are of average intelligence, calculus just won't make sense to you and that will end your STEM education right there. There are just more males with above average intelligence than there are females, so naturally more males will "survive" calculus to continue in STEM fields. On the other hand, there are more males with below average intelligence than females, which is one reason why most criminals are males.