def _merge(rect1, rect2):
    """
    Merge two seperate rectangles.

    'rect1', 'rect2' are rectangles, containing a tuple (x, y, w, h).
    """
    x1, y1, w1, h1 = rect1
    x2, y2, w2, h2 = rect2
    x = x1 if (x1 < x2) else x2
    y = y1 if (y1 < y2) else y2
    w = max(x1 + w1, x2 + w2) - x
    h = max(y1 + h1, y2 + h2) - y
    return (x, y, w, h)