More than you can shake a stick at

Hi - can anyone help with the origin of the phrase 'more than you can shake a stick at'? Any contributions gratefully received.

I think it's related to the old nautical term "enough space to swing a cat in", or thereabouts, which referred to the cat o'nine tails. When they
were punishing sailors, it referred to the space required to swing the device.