fixing bug #3345

Please see http://code.opencv.org/issues/3345

I am not quite sure if this change won't break the rest of things.
I would like to hear your feedback about this fix.