def intersection(r1, r2):
    """
    Helper method to obtain intersection of two rectangles
    r1 = [x1,y1,w1,h1]
    r2 = [x2,y2,w2,h2]
    returns [x,y,w,h]
    """
    assert len(r1) == 4 and len(r2) == 4, "Rectangles should be defined as [x,y,w,h]"

    rOut = [0, 0, 0, 0]
    rOut[0] = max(r1[0], r2[0])
    rOut[1] = max(r1[1], r2[1])
    rOut[2] = min(r1[0] + r1[2] - 1, r2[0] + r2[2] - 1) - rOut[0] + 1
    rOut[3] = min(r1[1] + r1[3] - 1, r2[1] + r2[3] - 1) - rOut[1] + 1

    if rOut[2] <= 0 or rOut[3] <= 0:
        return None
    return rOut