fixing issues from http://www.code.opencv.org/issues/2807