incorporated several critical fixes in EM implementation from Albert G (ticket #264)
incorporated several critical fixes in EM implementation from Albert G (ticket #264)

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