The problem is that you are ‘flattening’ Form XObject, but are not applying/concatentaing form Matrix to its children. There are couple of ways around this:
a) you can preserve form xobjects as xobjects (i.e. do not flatten the display list into a single stream).
b) apply forms matrix (and add extra clip path for form bbox) when flattening.
This is covered in more details in the following articles: