According to the IPv4
packet structure:

You have the version in the first octet, in the upper nibble. Version for IPv4
packets is "4" as you can see in the picture, but remember it has to be in the upper nibble, hence the 0x40
in the filter (64 in decimal base).
So what your filter do is grab the first byte of the IP header and AND it with 0xF0
to be sure it's keeping the version part (upper nibble) and then check if it is different from 0x40
(IPv4
packet).
What you could also have done is:
ip[0] & 0xf0 == 0x60
Which is the same as saying, keep only IPv6
packets. Version in a IPv6
packet is equal to 6. The position of the version information is the same as for a IPv4
header:
