I think the actual origins on this are still unclear, but the "shaking of the stick part" seems to stem from a gesture of threatening with an actual stick, with the original meaning loosely being "more than one can threaten." These days, it's used to indicate a large number of something, i.e. "more than you can shake a stick at" - which would imply that the actual number is more intimidating than the threatening stick shaking behavior. I know, that sounds wacky. Here are some additional links:
http://www.worldwidewords.org/qa/qa-sha2.htm
http://www.yaelf.com/aueFAQ/mifmrthnycnshkstck.shtml