fix bug 2432 for 2.4 branch

Same fix as https://github.com/Itseez/opencv/pull/3499 but then for the 2.4 branch since it was mentioned that there is no auto merge of branches into master anymore.