Bugfix 3186: unplugging webcam fix

Fixed the problem suggested in bug 3186
http://code.opencv.org/issues/3186