some fixes from http://code.opencv.org/issues/3733
some fixes from http://code.opencv.org/issues/3733

opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv