fixed 2 bugs reported by exvan (ticket #799)
fixed 2 bugs reported by exvan (ticket #799)

opencv/opencv,apavlenko/opencv,opencv/opencv,opencv/opencv,apavlenko/opencv,apavlenko/opencv,opencv/opencv,opencv/opencv,opencv/opencv,apavlenko/opencv,opencv/opencv,opencv/opencv,apavlenko/opencv,apavlenko/opencv,opencv/opencv,opencv/opencv