NVEncodeFrame causes driver reset

I am about to write a video processor which uses the NVIDIA API for encoding and decoding.

The decoded frame should be processed using CUDA and then be re-encoded.
for that, I have merged the two CUDA 5.5 SDK samples for h264 video decoding (GL) and encoding.

Now the problem:

NVEncodeFrame causes a driver reset (error 3) when called parallel to the video decoder in the OpenGL GLUT display function (from copyDecodedFrameToTexture).

What is the proper way to implement that without crash?
Also with regard to using the conexts in the right way

(NVEncodeFrame works fine if used without decoding at the same time)