You could use the same method as used by my program, but instead of using the bounding box area to as the comparison metric, use the minimum of the length of two adjacent sides. For example, in my code, change these lines:
bx1 (* (- (caadr box) (caar box)) (- (cadadr box) (cadar box)))
...
bx2 (* (- (caadr box) (caar box)) (- (cadadr box) (cadar box)))
To:
bx1 (min (- (caadr box) (caar box)) (- (cadadr box) (cadar box)))
...
bx2 (min (- (caadr box) (caar box)) (- (cadadr box) (cadar box)))