Jpeg tweaking // upmerge #2974 to master

Upmerge for #2974 (based on master) 
I've added more jpeg options to control using highgui API.
Could you please add it to next releases of OpenCV? 
Thank you.