Motion Only (Local) Bundle Adjustment - Camera pose optimization

Are there any direct implementation on OpenCV for Motion Bundle Adjustment like the one here:

If not, can someone give a python code example of how to solve it e.g. using cv.LMSolver / scipy.optimize.least_squares, given the 3dXYZPoints, 2dFeaturePoints from Image pair, the estimated pose (obtained by PnP), and CameraIntrinsics Matrix.

Thanks alot!