fixed bug #3187

see http://code.opencv.org/issues/3187