The word "sideways" can encompass "left side" and "right side". Is there a word to encompass "above" and "below"?
I agree with the other comments, that I am not sure "sideways" serves the purpose you would like.
But if you are not trying to exclude to the left or right, I would say "the surrounding area" or "the surroundings", as this would encompass anything in the vicinity of the object of interest.
Otherwise, I do not know of a word specifically for above or below, but not to the side, unless you want to be more technical and say "along the vertical axis of" or something of that sort which is less concise though than saying above or below.
To fit your algorithm, I would say that 'vertical rectangles' would fit your needs best, as Jontia suggested. If that doesn't work, you could use FumbleFingers' suggestion and term the groups 'X Rectangles' and 'Y/Z Rectangles' (either would be correct in a 2D space). If you need them in opposing groups of two, that would definitely work.
If neither of these options work, let me know why. I might be able to edit in a better suggestion.