Hello,
When inserting a new IDR frame, drain your pipeline and reset. There are only a few changes that are completely safe to do without a drain/reset. Use mfxExtEncoderResetOption=ON to make sure that a new sequence is started.
To ensure that mfxEncodeCtrl parameters correctly correspond to intended frame, allocate as many of them as surfaces used by the encoder.
Regards